package edu.npu.cv.dto;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonFormat;
import edu.npu.cv.entity.ActivityDO;
import edu.npu.cv.entity.ArticleDO;
import edu.npu.cv.entity.MemberDO;
import edu.npu.cv.utils.MarkDownUtil;
import lombok.Data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName MemberDTO
 * @Description TODO
 * @Author lele_Chang
 * @Date 2021/12/14 14:10
 */
@Data
public class ActivityDTO {

    private long id;

    private String title;

    private String coverImage;

    private String content;

    /** 分类id, 见{@link edu.npu.cv.enums.ArticleCategory}*/
    private long categoryId;

    /** 文章状态, 见{@link edu.npu.cv.enums.ArticleStatus} */
    private int status;

    /** 软删除状态, 见{@link edu.npu.cv.enums.ArticleDeleteStatus} */
    private int isDeleted;

    private Date createTime;

    private Date modifyTime;

    private String year;

    public static ActivityDTO ActivityDO2DTO(ArticleDO activityDO) {
        ActivityDTO activityDTO = new ActivityDTO();
        activityDTO.setId(activityDO.getId() >= 0 ? activityDO.getId() : 0L);
        activityDTO.setTitle(activityDO.getTitle());
        activityDTO.setCoverImage(activityDO.getCoverImage());
        activityDTO.setContent(MarkDownUtil.mdToHtml(activityDO.getContent()));
        activityDTO.setCategoryId(activityDO.getCategoryId());
        activityDTO.setStatus(activityDO.getStatus());
        activityDTO.setIsDeleted(activityDO.getIsDeleted());
        activityDTO.setCreateTime(activityDO.getCreateTime());
        activityDTO.setModifyTime(activityDO.getModifyTime());
        // //把年份截取出来
        DateFormat df = new SimpleDateFormat("yyyy");
        String year = df.format(activityDO.getCreateTime());
        activityDTO.setYear(year);
        return activityDTO;
    }
}
